package com.getpebble.android.main.sections.support.activity;

import android.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.NavUtils;
import android.view.MenuItem;
import com.getpebble.android.R;
import com.getpebble.android.core.PblBaseActivity;
import com.getpebble.android.main.activity.MainActivity;
import com.getpebble.android.onboarding.fragment.FirmwareUpdateFragment;

public class FirmwareUpdateActivity extends PblBaseActivity {
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_firmware_update);
    }

    public void onBackPressed() {
        if (!isFirmwareUpdating()) {
            exit();
        }
    }

    private void exit() {
        startActivity(new Intent(this, MainActivity.class));
        finish();
    }

    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() != 16908332) {
            return super.onOptionsItemSelected(item);
        }
        if (!isFirmwareUpdating()) {
            NavUtils.navigateUpFromSameTask(this);
        }
        return true;
    }

    private boolean isFirmwareUpdating() {
        Fragment currentFragment = getCurrentFragment();
        return currentFragment != null && (currentFragment instanceof FirmwareUpdateFragment) && ((FirmwareUpdateFragment) currentFragment).isInstalling();
    }
}
